package com.education.project.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.education.project.dao.LoginUserDao;
import com.education.project.model.LoginUser;
import com.education.project.model.LoginUserType;
import com.education.project.mapper.LoginUserMapper;
import com.education.project.mapper.LoginUserTypeMapper;
import com.education.project.service.LoginUserService;
import com.education.project.util.CommonsUtil;
import com.education.project.util.Page;

@Service
public class LoginUserServiceImpl implements LoginUserService {
	@Autowired
	private LoginUserMapper loginUserMapper;
	@Autowired
	private LoginUserTypeMapper loginUserTypeMapper;
	@Autowired
	private LoginUserDao loginUserDao;
	
	@Override
	public LoginUser getLoginUserByNamePasssword(String loginname, String password) {
		return loginUserMapper.getLoginUserByNamePasssword(loginname, password);
	}

	@Override
	public Page getLoginUserByPage(LoginUser param, Integer startPage, Integer limit) {
		int start = CommonsUtil.getStartRow(startPage, limit);
		Integer total = loginUserMapper.getcount(param);
		List<LoginUser> rows = loginUserMapper.getlimit(param, start, limit);
		for(LoginUser row:rows) {
			LoginUserType loginUserType = loginUserTypeMapper.get(row.getLoginUserTypeId());
			row.setLoginUserType(loginUserType);
		}
		return new Page(total, rows);
	}

	@Override
	public LoginUser getLoginUserByLoginname(String loginname) {
		return loginUserMapper.getLoginUserByLoginname(loginname);
	}

	@Override
	@Transactional
	public void saveLoginUser(LoginUser loginUser) {
		loginUserMapper.save(loginUser);
	}

	@Override
	@Transactional
	public void updateLoginUser(LoginUser loginUser) {
		loginUserMapper.update(loginUser);
	}

	@Override
	@Transactional
	public void removeLoginUser(Integer id) {
		loginUserMapper.remove(id);
	}

	@Override
	@Transactional
	public void updatePwdBatch(List list) {
		loginUserDao.updatePwdBatch(list);
	}

	@Override
	public Integer getLoginUserPassword(Integer id, String password) {
		return loginUserMapper.getLoginUserPassword(id, password);
	}

	@Override
	@Transactional
	public void updateLoginUserPassword(Integer id, String password) {
		loginUserMapper.updateLoginUserPassword(id, password);
	}

	@Override
	@Transactional
	public void updateLoginUserFullname(Integer id, String fullname) {
		loginUserMapper.updateLoginUserFullname(id, fullname);
	}

}
